#include<iostream>
using namespace std;
const int N = 1010;
typedef pair<int, int> PII;
int map[N][N];
bool st[N][N];
PII q[N * N];
int n;
void bfs(int x, int y, bool& has_higher, bool& has_lower)
{
	int hh = 0, tt = 0;
	q[0] = { x,y };
	st[x][y] = 1;
	while (hh <= tt) {
		PII temp = q[hh++];
		for (int i = temp.first - 1; i <= temp.first + 1; i++) {
			for (int j = temp.second - 1; j <= temp.second + 1; j++) {
				if (i < 0 || i >= n || j < 0 || j >= n)continue;
				if (map[i][j] != map[temp.first][temp.second]) {
					if (map[i][j] > map[temp.first][temp.second]) {
						has_higher = 1;	
					}
					else {
						has_lower = 1;
					}
				}
				else {
					if(!st[i][j])
					q[++tt] = { i,j };
					st[i][j] = 1;
				}
			}
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> map[i][j];
		}
	}
	int peak = 0;
	int valley = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (!st[i][j]) {
				bool has_higher = 0;
				bool has_lower = 0;
				bfs(i, j, has_higher, has_lower);
				if (!has_higher)peak++;
				if (!has_lower)valley++;
			}
		}
	}
	cout << peak << " " << valley << endl;
	return 0;
}